package com.hsjk.szwj.module.pay.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hsjk.szwj.module.pay.dal.dataobject.system.MchNotifyRecordDO;
import com.hsjk.szwj.module.pay.dal.mysql.IMchNotifyRecordMapper;
import org.springframework.stereotype.Service;

/**
 * @author chenjiawei
 * @desc 商户通知表 服务实现类
 * @Date 2023/08/22 16:39
 **/
@Service
public class MchNotifyRecordService
        extends ServiceImpl<IMchNotifyRecordMapper, MchNotifyRecordDO> {
    /** 根据订单号和类型查询 */
    public MchNotifyRecordDO findByOrderAndType(Long orderId, Integer orderType){
        return getOne(
                new LambdaQueryWrapper<MchNotifyRecordDO>()
                        .eq(MchNotifyRecordDO::getOrderId, orderId)
                        .eq(MchNotifyRecordDO::getOrderType, orderType)
        );
    }

    /** 查询支付订单 */
    public MchNotifyRecordDO findByPayOrder(Long orderId){
        return findByOrderAndType(orderId, MchNotifyRecordDO.TYPE_PAY_ORDER);
    }

    /** 查询退款订单订单 */
    public MchNotifyRecordDO findByRefundOrder(Long orderId){
        return findByOrderAndType(orderId, MchNotifyRecordDO.TYPE_REFUND_ORDER);
    }

    /** 查询退款订单订单 */
    public MchNotifyRecordDO findByTransferOrder(Long transferId){
        return findByOrderAndType(transferId, MchNotifyRecordDO.TYPE_TRANSFER_ORDER);
    }

    public Integer updateNotifyResult(Long notifyId, Integer state, String resResult){
        return baseMapper.updateNotifyResult(notifyId, state, resResult);
    }
}
